<?php

namespace app\admin\model\vip;

use think\Model;

/**
 * Info
 */
class Info extends Model
{
    // 表名
    protected $name = 'vip_info';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;
    protected $updateTime = false;

    // 追加属性
    protected $append = [
        'carInfo',
    ];


    public function getCarInfoAttr($value, $row): array
    {
        return [
            'car_code' => \app\admin\model\car\Info::whereIn('id', $row['car_info_ids'])->column('car_code'),
        ];
    }

    public function getCarInfoIdsAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            return explode(',', $value);
        }
        return $value;
    }

    public function setCarInfoIdsAttr($value): string
    {
        return is_array($value) ? implode(',', $value) : $value;
    }
}